home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: MegaDisc / MegaDisc 41 (1994-09)(MegaDisc Digital Publishing)(AU)(Disk 2 of 2).zip / MegaDisc 41 (1994-09)(MegaDisc Digital Publishing)(AU)(Disk 2 of 2).adf / ARexx_&_HBook / HyperText / Builder next >
Text File  |  1994-07-30  |  11KB  |  269 lines

  1.     /* */                                                             
  2.     
  3.     /*   Builder - A driver for a HyperBook implementation
  4.                    of hypertext methods for text perusal
  5.     
  6.          By John Collett     Hamilton, NZ   July, 1994       */
  7.     
  8.     
  9.     signal on syntax ; signal on error         /* Error trap */
  10.  
  11.     /* Placed here for convenience
  12.     If for some reason you want to process fewer pages than the whole file
  13.     - you might be at an exploratory or developmental stage - set templimit
  14.     to a non-zero value to process just that number of pages. */
  15.  
  16.     templimit = 0
  17.       
  18.     /*  Master1 AND (HyperBook OR HBReader) must be present. */
  19.      
  20.     a.1 = 'Master1' ; a.2 = 'HyperBook'; a.3 = 'HBReader'
  21.     if ~exists(a.1) then do ; say a.1 ' not found.' ; exit ; end
  22.     hpb = (exists(a.2)) ; hbr = (exists(a.3))
  23.     if ~(hpb | hbr) then do 
  24.      say 'Neither 'a.2' nor 'a.3' found.' ; exit ; end
  25.  
  26.     address command 'copy Master1 Master2'
  27.     
  28.    /* Launch HBReader, if present; if not, launch HyperBook. 
  29.      HyperBook (or HBReader) is being run from this external program. 
  30.      So calls to all HyperBook functions need to be prefixed by 'HML_'. */
  31.     
  32.      if hbr then address command 'HBReader Master2' 
  33.      else do ; address command 'HyperBook Master2'
  34.                call HML_TinyPanel() ; end
  35.     
  36.    /* Colour settings here. Change them if you want to. */
  37.     
  38.       c.0 = '69D' ; c.1 = '000' ; c.2 = 'FFF' ; c.3 = 'CEF'
  39.       c.4 = 'FA4' ; c.5 = 'E00' ; c.6 = '03F' ; c.7 = '0BF'
  40.       do i = 0 to 7 ; o = HML_SetPageRGB(':',i,X2D(c.i)) ; end
  41.       nleft = 8 ; ntop = 10 ; cr = '0a'x ; IsLabel = 0 ; main = 1
  42.       
  43.       /*  file = 'ltdocs'  */                                 /* Line A */
  44.       file = HML_FileRequest("Select your source file",'')    /* Line B */
  45.  
  46.     /* If you are working regularly on a given text (exploratory or
  47.     developmental work), then use line A of the above pair, quoting the
  48.     name of whatever file you are working on. Otherwise use line B.
  49.     Simply comment out the one you are not using.  */
  50.     
  51.     if open(fr, file, 'r') = 0 then exit 
  52.     
  53.     /*  Create a 'note' template to hold the patches of text.     */
  54.     nm = HML_CreateNote() ; call HML_SetBorder(nm,-1)
  55.     o = HML_ShadowStyle(nm,2) ; call HML_SetShadow(nm,-1)
  56.     
  57.     /*  Master2 starts life as a copy of Master1, a single page
  58.     containing templates of notes, buttons, and drawings for later use.
  59.     Further pages will be added to it, the final collection being
  60.     stored in the destination file.  The name of that file will be :
  61.     your file name, plus the extension '.ht'.  Here we copy required 
  62.     templates to the bin, and delete them from Master2.  
  63.     'Clone' followed by 'Delete' is less elegant that 'ReLocate', but
  64.     appears to produce a more complete copy (inc. colour settings etc). */
  65.  
  66.     small = HML_Clone('Small'(),'0:') ; call HML_Delete('Small'())
  67.     large = HML_Clone('Large'(),'0:') ; call HML_Delete('Large'())       
  68.     d1 = HML_Clone('Drawing1'(),'0:')        /* For coloured backgrounds */
  69.     d2 = HML_Clone('Drawing2'(),'0:')        /* For transparent overlay  */
  70.     call HML_Delete('Drawing1'()) ; call HML_Delete('Drawing2'()) 
  71.     call HML_Delete('Blurb1'()) ; call HML_Delete('Blurb2'()) 
  72.  
  73.     /*  Why TWO 'drawings' to mark highlighted words?  The coloured bar
  74.     has to be BEHIND the chunk it hilights, so as not to hide it.  The
  75.     other drawing, transparent, is IN FRONT OF the chunk, which is where
  76.     it has to be if it is to act as an active gadget. */
  77.   
  78.     d3 = HML_Clone('Head'(),'0:')            /* Box for page headline    */
  79.     d4 = HML_Clone('Header'(),'0:')          /* Text for page headline   */
  80.     call HML_Delete('Head'()) ; call HML_Delete('Header'())
  81.     
  82.     /* The clumsy doubling-up of 'Head' and 'Header' (when one little note
  83.     should have been enough) is to cater for the inability of HBReader to
  84.     make copies of a note, for highlighted chunks, which are smaller in 
  85.     either direction than the default size (61 x 23).  All very annoying!
  86.     */
  87.     
  88.     d5 = HML_Clone('Hook'(),'0:')            /* End-of-section marker    */
  89.     call HML_Delete('Hook'())
  90.     
  91.     /*      Main processing loop, page by page, starts here    */
  92.     
  93.     title = substr(file,index(file,':') + 1)
  94.     pageno = 1 ; labelno = 1 ; box. = ''
  95.  
  96.     do until eof(fr)
  97.  
  98.     /*  Read in text until text break is found or tally > 30   */
  99.      tally = 1 ; txt = '' ; nbox = 0
  100.      do forever
  101.       tally = tally + 1 ; line = readln(fr)
  102.       if eof(fr) | strip(line) = '.' then leave
  103.  
  104.       if substr(strip(line),1,3) = '.Bx' then do 
  105.         nbox = nbox + 1 ; tally = tally - 1 ; box.nbox = line ; iterate ; end  
  106.     
  107.       txt = txt || line || '0a'x ; if tally > 30 then leave
  108.       end
  109.       
  110.      linecount = tally - 1 + eof(fr)
  111.  
  112.      call MakeNote()               /* Put the text on the page */
  113.      call BuildGads()              /* Hilight marked text      */
  114.      if nbox > 0 then call DrawBox()    
  115.    
  116.      /* Jump to end of file if templimit has been reached */
  117.      if (templimit) > 0 & (pageno = templimit) then se = seek(fr,0,'e')
  118.     
  119.      if ~eof(fr) then do           /* Create the next page     */
  120.       pageno = pageno + 1 ; page = HML_CreatePage(':',pageno)
  121.       labelno = labelno + 1    
  122.       old = HML_GoToPage(page)
  123.       end
  124.     end                            /* of page-by-page loop     */
  125.  
  126.      call PNumbers()   /* A reverse sweep through pages to show nos etc. */
  127.   
  128.      /*  Store file with new name.  Close down.  Tidy up.  */
  129.     
  130.      call close(fr)
  131.      fileht = file || '.ht' ; b = HML_SaveHyperBook(fileht) 
  132.      cmd = 'copy Master1.info ' || fileht || '.info'
  133.      address command cmd 
  134.      address command 'Delete Master2 >NIL:' 
  135.      a = " Processing done." cr "Output saved as " || fileht cr
  136.      b = "Want to run it now?" cr
  137.      c = HML_GetResponse(a b)
  138.      if c then call HML_LoadHyperBook(fileht)
  139.           else call HML_QuitHyperBook()
  140.   
  141.     Finish:   exit
  142.     
  143.     /*     End of program : Functions follow */
  144.     
  145.     syntax: say 'Syntax : 'rc  errortext(rc) '. Line 'sigl ; signal 'Finish'
  146.     error: say 'Error : 'rc sigl ; signal 'Finish'
  147.  
  148.     MakeNote:
  149.     /* Is the first character a '.'?
  150.        If so: This is a 'note'.
  151.               Remove its first line.
  152.               Use the label as the name of the new page. */
  153.      firstchar = substr(strip(txt,'l'),1,1)
  154.      IsLabel = (firstchar = '.')
  155.     
  156.      if IsLabel then do
  157.       main = 0
  158.       dotpos = index(txt,'.',1) ; endpos = index(txt,'0a'x,1)
  159.       label = substr(txt,dotpos+1,endpos-1)
  160.       label = strip(compress(label,'.'||'0a'x)) 
  161.       labelno = 1 ; title = label
  162.       txt = substr(txt,endpos + 1,length(txt)) 
  163.       newname = title || ' 1'
  164.       end
  165.      else if main then newname = title || ' ' || pageno
  166.                   else newname = title || ' ' || labelno
  167.     
  168.     ctxt = compress(txt,'`')                  /* Remove the ` markers */
  169.     p =  HML_CurrentPage() ; note = HML_Clone(nm,'0:') 
  170.     o =  HML_SetName(HML_CurrentPage(),newname)
  171.     call HML_ScaleToSize(note,620,linecount * 8 + 8)
  172.     call HML_SetPosition(note,nleft,ntop) 
  173.     call HML_InsertText(note,ctxt,0) ; note = HML_ReLocate(note, p)
  174.     
  175.     h =  HML_Clone(d3,'0:')                     /* Box for page title   */
  176.     call HML_ScaleToSize(h,length(newname)*8 + 24,10)
  177.     call HML_SetActionMacro(h,'FrameSpec') ; h =  HML_Relocate(h,':')
  178.     h2 = HML_Clone(d4,'0:')                    /* Text of page title   */
  179.     call HML_ScaleToSize(h2,length(newname)*8 + 24,10)
  180.     o =  HML_ReplaceText(h2,newname,0,-1)
  181.     call HML_SetActionMacro(h2,'FrameSpec'); h =  HML_Relocate(h2,':')
  182.    return
  183.  
  184.     BuildGads:
  185.     /*  Any words or phrases in the source text enclosed `thus` will be
  186.      hi-lighted.  In standard hypertext fashion, when clicked on, they
  187.      take you to the page containing related text. */
  188.  
  189.     /* Cut the note text into lines */
  190.     call HML_InterActive(1)
  191.     chunk. = '' ; pos = -1 ; start = 1 ; linecount = 0 ; markcount = 0
  192.     do until pos = 0
  193.      pos = index(txt,'0a'x,start) ; if pos = 0 then leave
  194.         
  195.      linecount = linecount + 1 ; thisline = substr(txt,start,pos-start+1)
  196.      if length(thisline) > 2 then
  197.  
  198.      /* Find any marked words in the line */
  199.       mark1 = -1 ; aa = 1 ; adj = 0
  200.       do until mark1 = 0
  201.        mark1 = index(thisline,"`",aa) ; if mark1 = 0 then leave
  202.  
  203.        /* Find partner, or next space, or end of line. */
  204.        mark2 = index(thisline,"`",mark1+1)
  205.        if mark2 = 0 then do  
  206.          mark2 = index(thisline," ",mark1+1)
  207.          if mark2 = 0 then mark2 = length(thisline)
  208.          end
  209.        markcount = markcount + 1
  210.        adj = adj + 1           /* To adjust text when markers removed   */
  211.        chunk.markcount = substr(thisline,mark1+1,mark2-mark1-1)   
  212.        charleft = nleft + mark1*8 + 14 - adj*16
  213.        chardown = ntop + 1 + linecount*8
  214.        call MakeGadget()       /* Build a gadget for that chunk of text */
  215.        aa = mark2 + 1
  216.        end                     /* of that line treatment */
  217.       start = pos + 1
  218.      end                       /* of dealing with markers on that page  */
  219.      return
  220.  
  221.     MakeGadget:
  222.      call HML_InterActive(0)               /* For less flickering */
  223.      len = length(chunk.markcount) * 8
  224.      
  225.      Dr1= HML_Clone(d1,'0:')              /* Coloured bar, behind */
  226.      call HML_ScaleToSize(Dr1,len+4,8)
  227.      call HML_SetPosition(Dr1,charleft+1,chardown-8)
  228.      o =  HML_SetName(Dr1,chunk.markcount || '2')
  229.      gad= HML_Relocate(Dr1,':') ; gad = HML_ObjectToBack(gad) 
  230.     
  231.      Dr2= HML_Clone(d2,'0:')          /* Transparent, in front, active */
  232.      call HML_ScaleToSize(Dr2,len+10,8)
  233.      call HML_SetPosition(Dr2,charleft-2,chardown-8)
  234.      act= HML_SetActionMacro(Dr2,'Link')
  235.      o =  HML_SetName(Dr2,chunk.markcount) ; gad = HML_Relocate(Dr2,':')
  236.      return
  237.          
  238.     /* Back through all pages to add cosmetic touches */
  239.     PNumbers:
  240.      num = HML_NumPages() ; tag = '/' || num
  241.      pg1 = HML_SearchName('1:','PageNumber') ; oldstem = ''
  242.      do i = num to 1 by -1
  243.       op = HML_GoToPage(i || ':') ; cp = HML_CurrentPage()
  244.       /* Numbering */
  245.       pg = HML_Clone(pg1,cp) ; o = HML_ReplaceText(pg,i || tag,0,-1)
  246.     
  247.       /* Marking last page of each section */
  248.       thisname = HML_GetName(cp) ; parse var thisname stem n
  249.       if stem ~= oldstem then do
  250.        ho = HML_Clone(d5,'0:') ; hook = HML_Relocate(ho,':') ; end
  251.       oldstem = stem
  252.      end
  253.     return 
  254.  
  255.     DrawBox: procedure expose small large nbox box.
  256.      do j = 1 to nbox
  257.       call HML_InterActive(0)
  258.       line = box.j ; parse var line cmd l ',' t ',' w ',' h ',' bg .
  259.       mini = (w < 62 | h < 24) ; if mini then box= HML_Clone(small,':') 
  260.       else box= HML_Clone(large,':')
  261.       if (mini = 0) & (bg ~= '') then bakg = HML_SetBackGround(box,bg)
  262.       b =  HML_SetBorder(box,2) ; b = HML_SetShadow(box,1)
  263.       call HML_SetPosition(box,strip(l),t) 
  264.       call HML_ScaleToSize(box,w,strip(h))
  265.       f =  HML_ObjectToBack(box)
  266.      end
  267.     return
  268.                          /*    end    */
  269.